package com.xinqi.modules.prepare.prepare.factory;


import com.xinqi.common.base.error.CommonErrors;
import com.xinqi.common.base.response.PageInfo;
import com.xinqi.common.base.response.R;
import com.xinqi.modules.prepare.prepare.client.PreparePrepareClient;
import com.xinqi.modules.prepare.prepare.dto.req.PrepareCreateDTO;
import com.xinqi.modules.prepare.prepare.dto.req.PrepareQueryDTO;
import com.xinqi.modules.prepare.prepare.dto.req.PrepareUpdateDTO;
import com.xinqi.modules.prepare.prepare.dto.rsp.PrepareResultDTO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

/**
 * 备课区降级处理
 *
 * @author: wenjie
 * @date: 2023/10/30
 */
@Slf4j
@Component
public class PrepareFallbackFactory implements FallbackFactory<PreparePrepareClient> {

    @Override
    public PreparePrepareClient create(Throwable throwable) {
        log.error("云课本服务调用失败:{}", throwable.getMessage());
        return new PreparePrepareClient() {
            @Override
            public R<PageInfo<PrepareResultDTO>> page(PrepareQueryDTO dto) {
                return R.error(CommonErrors.INTERNAL_SERVER_ERROR.getCode(), null);
            }

            @Override
            public R<PrepareResultDTO> findById(Long id) {
                return R.error(CommonErrors.INTERNAL_SERVER_ERROR.getCode(), null);
            }

            @Override
            public R<Long> insert(PrepareCreateDTO dto) {
                return R.error(CommonErrors.INTERNAL_SERVER_ERROR.getCode(), null);
            }

            @Override
            public R<Boolean> update(Long id, PrepareUpdateDTO dto) {
                return R.error(CommonErrors.INTERNAL_SERVER_ERROR.getCode(), null);
            }

            @Override
            public R<Boolean> delete(Long id) {
                return R.error(CommonErrors.INTERNAL_SERVER_ERROR.getCode(), null);
            }
        };
    }
}